package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark74Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark74 extends BaseMark {

    LayoutWatermark74Binding binding;

    public Mark74(@NonNull Context context) {
        super(context);
    }

    public Mark74(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark74(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark74Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.mid, binding.binding16);
        } else {
            binding = LayoutWatermark74Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title74", binding.binding1);
        setText(binding.binding3, "time74", binding.binding2);
        setTime(binding.binding3, new SimpleDateFormat("HH:mm"));
        setTime(binding.binding4, new SimpleDateFormat("yyyy.MM.dd"));
        setWeek(binding.binding5);

        setText(binding.binding7, "didian74", binding.binding6);
        setText(binding.binding9, "visit74", binding.binding8);
        setText(binding.binding11, "object74", binding.binding10);

        setText(binding.binding13, "content74", binding.binding12);
        setText(binding.binding15, "beizhu74", binding.binding14);
        setText(binding.binding18, "pic74", binding.binding17);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title74", "标题"));
        list.add(new EditItem("time74", "时间", true));
        list.add(new EditItem("didian74", "地点"));

        list.add(new EditItem("visit74", "拜访人"));
        list.add(new EditItem("object74", "拜访对象"));
        list.add(new EditItem("content74", "拜访内容"));

        list.add(new EditItem("beizhu74", "备注"));
        list.add(new EditItem("pic74", "拍照人"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("HH:mm"));
            setTime(binding.binding4, new SimpleDateFormat("yyyy.MM.dd"));
            setWeek(binding.binding5);
        } else {
            super.onValueChange(item);
        }
    }
}
